require('../less/login.less')
document.ready(function () {
    document.querySelector('.d1').addEventListener('click', function () {
        location.href = 'register.html';
    })
    let an = document.querySelector('#an');
    let pwd = document.querySelector('#pwd');
    let inpu = document.querySelector('#inpu');

    document.querySelector('#btn').addEventListener('click', function () {
        let anVle = an.value;
        /* 正则验证 */
        if (!(/^1[3-9]\d{9}$/.test(anVle))) {
            inpu.textContent = '请输入正确的账号'
        }
        let pwdVlee = pwd.value;
        if (!pwdVlee) {
            inpu.textContent = '内容不能为空'
        }
        inpu.textContent = '';
        /* ajax */
        window.$http.post("/users/login", { account:anVle, password:pwdVlee }, function (res) {

            if (res.status === 0) {
                localStorage.setItem('uid',res.data.user.userId)
                window.$utils.tips('登录成功')

                setTimeout(() => {
                    location.href = 'home.html'
                }, 2000);
            } else {
                window.$utils.tips('信息不正确', "😒", 2000)
                //失败
            }
            ok.textContent = res.msg;
        })





    })





})